package com.bff.gaia.runtime.maqy;

import com.bff.gaia.runtime.maqy.service.Rate;

import java.io.Serializable;

public class HostInfo implements Serializable {
	private String hostName;
	private String ip;
	private int subTaskIdx;
	private Rate rate;

	public HostInfo(String hostName, String ip, Rate rate, int subTaskIdx) {
		this.hostName = hostName;
		this.ip = ip;
		this.rate = rate;
		this.subTaskIdx = subTaskIdx;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof HostInfo) {
			return this.hostName.equals(((HostInfo) obj).getHostName()) && this.ip.equals(((HostInfo) obj).getIp());
		}

		return false;
	}

	@Override
	public String toString() {
		return String.format("%s@%s(subTaskIdx: %d), rate: %s", this.ip, this.hostName, subTaskIdx, this.rate.toString());
	}

	public String value() {
		return String.format("%s@%s", this.ip, this.hostName);
	}

	// ========setters========

	public void setHostName(String hostName) {
		this.hostName = hostName;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public void setRate(Rate rate) {
		this.rate = rate;
	}

	public void setSubTaskIdx(int subTaskIdx) {
		this.subTaskIdx = subTaskIdx;
	}

	// =========getters=========

	public String getHostName() {
		return hostName;
	}

	public String getIp() {
		return ip;
	}

	public Rate getRate() {
		return rate;
	}

	public int getSubTaskIdx() {
		return subTaskIdx;
	}
}